package org.gangcai.mac.shop.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import org.gangcai.mac.shop.R;
import org.gangcai.mac.shop.adapter.AnimationAdapter;
import org.gangcai.mac.shop.adapter.AnimationAdapter1;
import org.gangcai.mac.shop.api.AppAPI;
import org.gangcai.mac.shop.bean.CommonResonseBean;
import org.gangcai.mac.shop.bean.HomeDataBean;
import org.gangcai.mac.shop.bean.PostsArticleBaseBean;
import org.gangcai.mac.shop.bean.SlideBean;
import org.gangcai.mac.shop.common.MultiStatusActivity;
import org.gangcai.mac.shop.constants.Constant;
import org.gangcai.mac.shop.entity.MultipleItem;
import org.gangcai.mac.shop.manager.RetrofitManager;
import org.gangcai.mac.shop.manager.RetrofitManageres;
import org.gangcai.mac.shop.oberver.CommonObserver;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;

import static org.gangcai.mac.shop.constants.Constant.CODE_SUCC;

public class Animation1Activity extends MultiStatusActivity {

    @BindView(R.id.recyclerview_anomation1)
    RecyclerView recyclerview_anomation1;

    private AnimationAdapter1 animationAdapter1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        initTitleBarView(titlebar, "城库找车");
        LogUtils.e("loadAnimation1Fragment");
        RetrofitManageres.getInstance().create(AppAPI.class).HomeData("Portal","list","indexJson","2")
                .observeOn(AndroidSchedulers.mainThread())
                .compose(this.<HomeDataBean>bindToLifecycle())
                .subscribe(new CommonObserver<HomeDataBean>(multipleStatusView) {
                    @Override
                    public void onSuccess(HomeDataBean value) {
                        if (value.getCode() == CODE_SUCC) {
                            animationAdapter1 = new AnimationAdapter1(Animation1Activity.this,value.getReferer().getPosts());
                            animationAdapter1.openLoadAnimation();
                            animationAdapter1.setNotDoAnimationCount(3);
                            recyclerview_anomation1.setLayoutManager(new GridLayoutManager(Animation1Activity.this, 1));

                            animationAdapter1.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
                                @Override
                                public void onLoadMoreRequested() {

                                }
                            });
                            animationAdapter1.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                    PostsArticleBaseBean postsArticleBaseBean=value.getReferer().getPosts().get( position );
                                    Bundle bundle = new Bundle();
                                    String postID=postsArticleBaseBean.getObject_id();
                                    String cid=postsArticleBaseBean.getTerm_id();
                                    String webString="http://thinkcmf.500-china.com/index.php?g=&m=article&a=index&id="+postID+"&cid="+cid;
                                    bundle.putString("webString", webString);
                                    bundle.putString("title" , postsArticleBaseBean.getPost_title());
                                    bundle.putString("postID" , postID);
                                    ActivityUtils.startActivity(bundle, Animation1Activity.this, WebActivity.class);
                                }
                            });
                            recyclerview_anomation1.setAdapter(animationAdapter1);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        Toast.makeText(Animation1Activity.this, R.string.network_err, Toast.LENGTH_LONG).show();
                    }
                });
    }

    @Override
    public int getContentView() {
        return R.layout.activity_animation;
    }


}
